home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / gg / gengetopt-2.6.lha / gengetopt-2.6 / src / scanner.l < prev    next >
Text File  |  2002-03-01  |  3KB  |  95 lines

  1. /**
  2.  * Copyright (C) 1999, 2000, 2001  Free Software Foundation, Inc.
  3.  *
  4.  * This file is part of GNU gengetopt 
  5.  *
  6.  * GNU gengetopt is free software; you can redistribute it and/or modify 
  7.  * it under the terms of the GNU General Public License as published by 
  8.  * the Free Software Foundation; either version 2, or (at your option) 
  9.  * any later version. 
  10.  *
  11.  * GNU gengetopt is distributed in the hope that it will be useful, but 
  12.  * WITHOUT ANY WARRANTY; without even the implied warranty of 
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  14.  * Public License for more details. 
  15.  *
  16.  * You should have received a copy of the GNU General Public License along 
  17.  * with gengetopt; see the file COPYING. If not, write to the Free Software 
  18.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  19.  */
  20.  
  21.  
  22. %{
  23. #include <string.h>
  24. #include "argsdef.h"
  25. #include "parser.h"
  26. extern int gengetopt_count_line;
  27.  
  28. static void update_count_line (char *str);
  29.  
  30. %}
  31.  
  32. %%
  33.  
  34. [Pp][Aa][Cc][Kk][Aa][Gg][Ee]           return TOK_PACKAGE;
  35. [Vv][Ee][Rr][Ss][Ii][Oo][Nn]           return TOK_VERSION;
  36. [Oo][Pp][Tt][Ii][Oo][Nn]           return TOK_OPTION;
  37. [Ss][Tt][Rr][Ii][Nn][Gg]    yylval.argtype = ARG_STRING; return TOK_ARGTYPE;
  38. [Ii][Nn][Tt]            yylval.argtype = ARG_INT; return TOK_ARGTYPE;
  39. [Ss][Hh][Oo][Rr][Tt]        yylval.argtype = ARG_SHORT; return TOK_ARGTYPE;
  40. [Ll][Oo][Nn][Gg]        yylval.argtype = ARG_LONG; return TOK_ARGTYPE;
  41. [Ff][Ll][Oo][Aa][Tt]        yylval.argtype = ARG_FLOAT; return TOK_ARGTYPE;
  42. [Dd][Oo][Uu][Bb][Ll][Ee]    yylval.argtype = ARG_DOUBLE; return TOK_ARGTYPE;
  43. [Ll][Oo][Nn][Gg][Dd][Oo][Uu][Bb][Ll][Ee]   yylval.argtype = ARG_LONGDOUBLE; return TOK_ARGTYPE;
  44. [Ll][Oo][Nn][Gg][Ll][Oo][Nn][Gg]   yylval.argtype = ARG_LONGLONG; return TOK_ARGTYPE;
  45. [Yy][Ee][Ss]                   return TOK_YES;
  46. [Nn][Oo]                   return TOK_NO;
  47. [Ff][Ll][Aa][Gg]               return TOK_FLAG;
  48. [Oo][Nn]                   yylval.bool = 1; return TOK_ONOFF;
  49. [Oo][Ff][Ff]                   yylval.bool = 0; return TOK_ONOFF;
  50. [Pp][Uu][Rr][Pp][Oo][Ss][Ee]           return TOK_PURPOSE;
  51. [Dd][Ee][Ff][Aa][Uu][Ll][Tt]               return TOK_DEFAULT;
  52.  
  53. "=" { return '='; }
  54.  
  55. [[:alnum:]-]            yylval.chr = yytext[0]; return TOK_CHAR;
  56. \"[^\"\n]*\"    {
  57.   /* if you add or remove symbols, change canonize_vars
  58.      function */
  59.   yytext [strlen(yytext) - 1] = 0;
  60.   yylval.str = yytext + 1;
  61.   return TOK_STRING;
  62. }
  63.  
  64. \"[^\"]*\"    {
  65.   /* if you add or remove symbols, change canonize_vars
  66.      function */
  67.   yytext [strlen(yytext) - 1] = 0;
  68.   yylval.str = yytext + 1;
  69.   update_count_line (yylval.str);
  70.   return TOK_MLSTRING;
  71. }
  72.  
  73. [ \t]+                /* eat spaces */
  74. #[^\n]*                /* comments begin with # in any place */
  75. \n                gengetopt_count_line++; /* return '\n'; */
  76.  
  77. .        { 
  78.   return 1000; /* little hack to produce a parse error too. */ 
  79. }
  80.  
  81. %%
  82.  
  83. /*
  84.   Otherwise '\n' within a TOK_MLSTRING would not be counted
  85. */
  86. void
  87. update_count_line (char *str)
  88. {
  89.   char *p;
  90.  
  91.   for (p = str; *p; ++p)
  92.     if (*p == '\n')
  93.       ++gengetopt_count_line;
  94. }
  95.